package de.jmda.mview.fx.node.typeshape;

import javax.lang.model.element.TypeElement;

import javafx.application.Application;
import javafx.scene.Group;
import de.jmda.fx.sandbox.Sandbox;
import de.jmda.mproc.TypeElementDictionarySingleton;
import de.jmda.mproc.TypeElementFactory;
import de.jmda.mview.ElementFactory.CPub;
import de.jmda.mview.ElementFactory.CPubOwned;
import de.jmda.mview.ElementFactory.CPubOwner;
import de.jmda.mview.ElementFactory.CPubSub;
import de.jmda.mview.fx.MViewGroup;
import de.jmda.mview.typeshape.DisplayOptionsModelUtil;
import de.jmda.sample.person_contact.model.Address;
import de.jmda.sample.person_contact.model.Contact;
import de.jmda.sample.person_contact.model.ContactInfo;
import de.jmda.sample.person_contact.model.EMail;
import de.jmda.sample.person_contact.model.Person;
import de.jmda.sample.person_contact.model.Phone;

public class SandboxMViewGroup
    extends Sandbox
{
	private MViewGroup mViewGroup;

	public static void main(String[] args)
	{
		Application.launch(args);
	}

	@Override
	protected Group getGroup()
	{
		if (mViewGroup == null)
		{
			mViewGroup = new MViewGroup();
		}

		return mViewGroup.get();
	}

	@Override
	protected void populateGroup()
  {
		for (TypeElement typeElement :
		     TypeElementDictionarySingleton.instance().getAll())
		{
			System.out.println(typeElement.getQualifiedName().toString());
		}
		populateFromElementFactory();
//		populateFromSample();
  }

	private void populateFromSample()
	{
		DisplayOptionsModelUtil displayOptionsModelUtil =
				DisplayOptionsModelUtil.create();

		Typeshape contact =
				new Typeshape(
						TypeElementFactory.get("jmda.sample", Contact.class),
						displayOptionsModelUtil);
		Typeshape person =
				new Typeshape(
						TypeElementFactory.get("jmda.sample", Person.class),
						displayOptionsModelUtil);
		Typeshape contactInfo =
				new Typeshape(
						TypeElementFactory.get("jmda.sample", ContactInfo.class),
						displayOptionsModelUtil);
		Typeshape phone =
				new Typeshape(
						TypeElementFactory.get("jmda.sample", Phone.class),
						displayOptionsModelUtil);
		Typeshape eMail =
				new Typeshape(
						TypeElementFactory.get("jmda.sample", EMail.class),
						displayOptionsModelUtil);
		Typeshape address =
				new Typeshape(
						TypeElementFactory.get("jmda.sample", Address.class),
						displayOptionsModelUtil);

		mViewGroup.add(contact);
		mViewGroup.add(person);
		mViewGroup.add(contactInfo);
		mViewGroup.add(phone);
		mViewGroup.add(eMail);
		mViewGroup.add(address);
	}

	private void populateFromElementFactory()
	{
		DisplayOptionsModelUtil displayOptionsModelUtil =
				DisplayOptionsModelUtil.create();

		Typeshape typeshapeOwner =
				new Typeshape(
						TypeElementFactory.get("jmda.mview", CPubOwner.class),
						displayOptionsModelUtil);

		Typeshape typeshapeOwned =
				new Typeshape(
						TypeElementFactory.get("jmda.mview", CPubOwned.class),
						displayOptionsModelUtil);

		Typeshape typeshapeSuper =
				new Typeshape(
						TypeElementFactory.get("jmda.mview", CPub.class),
						displayOptionsModelUtil);

		Typeshape typeshapeSub =
				new Typeshape(
						TypeElementFactory.get("jmda.mview", CPubSub.class),
						displayOptionsModelUtil);

//		mViewGroup.add(typeshapeOwner);
		mViewGroup.add(typeshapeOwned);
//		mViewGroup.add(typeshapeSuper);
//		mViewGroup.add(typeshapeSub);
	}
}